home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 016 / source.files / putpict.c < prev    next >
C/C++ Source or Header  |  1995-03-17  |  4KB  |  90 lines

  1. /** putpict.c ***************************************************/
  2. /* PutPict().  Given a BitMap and a color map in RAM on the     */
  3. /* Amiga, outputs as an ILBM.  See /iff/ilbm.h & /iff/ilbmw.c.    */
  4. /*                   23-Jan-86                  */
  5. /*                                                              */
  6. /* By Jerry Morrison and Steve Shaw, Electronic Arts.           */
  7. /* This software is in the public domain.                       */
  8. /*                                                              */
  9. /* This version for the Commodore-Amiga computer.               */
  10. /*                                                              */
  11. /****************************************************************/
  12. #include "iff/intuall.h"
  13. #include "iff/gio.h"
  14. #include "iff/ilbm.h"
  15. #include "iff/putpict.h"
  16.  
  17. #define MaxDepth 5
  18. static IFFP ifferror = 0;
  19.  
  20. #define CkErr(expression)  {if (ifferror == IFF_OKAY) ifferror = (expression);}
  21.     
  22. /*****************************************************************************/
  23. /* IffErr                                                                    */
  24. /*                                                                           */
  25. /* Returns the iff error code and resets it to zero                          */
  26. /*                                                                           */
  27. /*****************************************************************************/
  28. IFFP IffErr()
  29.    {
  30.    IFFP i;
  31.    i = ifferror;
  32.    ifferror = 0;
  33.    return(i);
  34.    }
  35.  
  36. /*****************************************************************************/
  37. /* PutPict()                                                                 */
  38. /*                                                                           */
  39. /* Put a picture into an IFF file                                            */
  40. /* Pass in mask == NULL for no mask.                                         */
  41. /*                                                                           */
  42. /* Buffer should be big enough for one packed scan line                      */
  43. /* Buffer used as temporary storage to speed-up writing.                     */
  44. /* A large buffer, say 8KB, is useful for minimizing Write and Seek calls.   */
  45. /* (See /iff/gio.h & /iff/gio.c).                                            */
  46. /*****************************************************************************/
  47.     
  48. BOOL PutPict(file, bm, pageW, pageH, colorMap, buffer, bufsize)
  49.       LONG file; struct BitMap *bm; 
  50.     WORD pageW,pageH;
  51.     WORD *colorMap;
  52.       BYTE *buffer;  LONG bufsize;
  53.     {
  54.     BitMapHeader bmHdr;
  55.     GroupContext fileContext, formContext;
  56.         
  57.     ifferror = InitBMHdr(&bmHdr,
  58.     bm, 
  59.     mskNone, 
  60.     cmpByteRun1, 
  61.     0,
  62.     pageW, 
  63.     pageH );
  64.     
  65. /* use buffered write for speedup, if it is big-enough for both
  66.  * PutBODY's buffer and a gio buffer.*/
  67. #define BODY_BUFSIZE 512
  68.     if (ifferror == IFF_OKAY  &&  bufsize > 2*BODY_BUFSIZE) {
  69.     if (GWriteDeclare(file, buffer+BODY_BUFSIZE, bufsize-BODY_BUFSIZE) < 0)
  70.         ifferror = DOS_ERROR;
  71.     bufsize = BODY_BUFSIZE;
  72.     }
  73.     
  74.     CkErr(OpenWIFF(file, &fileContext, szNotYetKnown) );
  75.     CkErr(StartWGroup(&fileContext, FORM, szNotYetKnown, ID_ILBM, &formContext) );
  76.  
  77.     CkErr(PutCk(&formContext, ID_BMHD, sizeof(BitMapHeader), (BYTE *)&bmHdr));
  78.  
  79.     if (colorMap!=NULL)
  80.     CkErr( PutCMAP(&formContext, colorMap, (UBYTE)bm->Depth) );
  81.     CkErr( PutBODY(&formContext, bm, NULL, &bmHdr, buffer, bufsize) );
  82.  
  83.     CkErr( EndWGroup(&formContext) );
  84.     CkErr( CloseWGroup(&fileContext) );
  85.     if (GWriteUndeclare(file) < 0  &&  ifferror == IFF_OKAY)
  86.     ifferror = DOS_ERROR;
  87.     return( (BOOL)(ifferror != IFF_OKAY) );
  88.     }    
  89.  
  90.